package com.xjh.serverinspect.security.controller;

import com.xjh.serverinspect.security.NoResponseEncrypt;
import com.xjh.serverinspect.security.model.UsernamePasswordDTO;
import com.xjh.serverinspect.security.service.SecurityService;
import com.xjh.serverinspect.util.ResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 安全相关的Controller
 * </p>
 *
 * @author xujinghui
 * @since 2024-10-16
 */
@RestController
@RequestMapping("/security")
@Slf4j
public class SecurityController {

    @Resource
    private SecurityService securityService;

    @PostMapping("/login")
    public ResponseDTO login(@RequestBody UsernamePasswordDTO usernamePasswordDTO) {
        return securityService.login(usernamePasswordDTO);
    }

    @PostMapping("/refreshAccessToken")
    public ResponseDTO refreshAccessToken(String refreshToken) {
        return securityService.refreshAccessToken(refreshToken);
    }

    @GetMapping("/rsaPublicKey")
    @NoResponseEncrypt
    public ResponseDTO rsaPublicKey() {
        return securityService.rsaPublicKey();
    }

}
